#include<stdio.h>
int a[50000],b[50000],c[50000];
int kru(int n)
{
   while(a[n]!=-1)
       n=a[n];
   return n;
}
int main()
{
   int i,m,n,p,q,k=1,flag,num,node;
   while(scanf("%d%d",&m,&n),m>=0||n>=0)
   {
       for(i=0;i<50000;i++)
       {
          a[i]=-1; b[i]=-1; c[i]=-1;
       }
       c[n]=m;
       num=1; node=2;
       b[m]=0; b[n]=0;
       flag=1;
       if(m==n)
           flag=0;
       if(m==0&&n==0)
       {
           flag=1;
           goto loop;
       }
       a[m]=n;
       while(scanf("%d%d",&m,&n),m!=0||n!=0)
       {
           if(flag==1)
           {
               if(c[n]==-1)
                   c[n]=m;
               else
                   flag=0;
              if(b[m]==-1)
               { 
                  node++;
                  b[m]=0;
               }
              if(b[n]==-1)
               {
                  node++;
                  b[n]=0;
               }
              num++;
              p=kru(m); q=kru(n);
              if(p==q)
                  flag=0;
              else
                  a[p]=q;
           }
       }
       if(num!=node-1)
           flag=0;
loop:    if(flag==0)
           printf("Case %d is not a tree.\n",k++);
       else
           printf("Case %d is a tree.\n",k++);
   }
   return 0;
}
